﻿using EntityModels.E09.Files;
using IRepositories;
using Microsoft.EntityFrameworkCore;
using ORM;

namespace Repositories
{
    public class FileHashRepository : IFileHashRepository
    {
        private readonly PSPDbContext context;

        public FileHashRepository(PSPDbContext context)
        {
            this.context = context;
        }

        public async Task<FileHash> CreateAsync(FileHash fileHash)
        {
            try
            {
                await context.FileHashs.AddAsync(fileHash);
                await context.SaveChangesAsync();
                return fileHash;
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public async Task<FileHash> FindAsync(string hash)
        {
            return await context.FileHashs.FirstOrDefaultAsync(x => x.Hash.Equals(hash));
        }
    }
}
